package cn.ac.radi.userver.waste.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ProcessUtil {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    public void writeProcessStream(Process proc){

        BufferedReader br=null;
        BufferedReader bo=null;
        BufferedReader be=null;
        String line = null;

        try{
            br=new BufferedReader(
                    new InputStreamReader(
                            proc.getInputStream()
                    )
            );

            while((line=br.readLine())!=null){
                logger.info(line);
            }

            be=new BufferedReader(
                    new InputStreamReader(
                            proc.getErrorStream()
                    )
            );
            while((line=be.readLine())!=null){
                String msg = new String(line.getBytes(), "UTF-8");
                logger.info(msg);
                String gbk = new String(line.getBytes(), "GBK");
                logger.info(gbk);
            }

//            bo=new BufferedReader(
//                    new OutputStream(
//                            proc.getOutputStream()
//                    )
//            );
//            while((line=bo.readLine())!=null){
//                logger.info(line);
//            }
        }
        catch (IOException e){
            e.printStackTrace();
        }
    }
}
